//污染追踪溯源
Ext.define("Admin.view.emergencyDispatch.ContaminantsTrack", {
    extend: "Admin.common.container.BaseContainer",
    xtype: "contaminantsTrack",
    alias: "contaminantsTrack",
    requires: [
        "Admin.store.emergencyDispatch.NewPlanEventList",
        'Admin.common.panel.AgsMap',
        'Admin.common.data.proxy.API',
        'Admin.common.form.field.DateTime',
        'Admin.common.form.field.DateTimeField'
    ],
    controller: "contaminantsTrack",
    viewmodel: {
        type: "contaminantsTrack"
    },
    layout: {
        type: "hbox",
        align: "stretch"
    },
    listeners: {
        activate: 'eventListRender'
    },
    items: [{
            border: true,
            flex: 0.7,
            xtype: "agsMap",
            reference: "map",
            listeners: {
                mapInit: "onMapInit"
            }
        },
        {
            xtype: "panel",
            flex: 0.3,
            margin: '0 0 0 10',
            items: [{
                    xtype: "form",
                    border: true,
                    flex: 0.55,
                    title: "条件设置",
                    layout: "anchor",
                    padding: '0 0 0 0',
                    defaults: {
                        anchor: "100%",
                        margin: "10 10 0 10",
                        labelWidth: 120,
                        labelAlign: "right"
                    },
                    items: [{
                            xtype: "combobox",
                            fieldLabel: "选择应急事件",
                            reference: "evenCd",
                            id: 'zzsyEventCd',
                            valueField: "evenCd",
                            displayField: "evenNm",
                            emptyText: "请选择应急事件",
                            queryMode: "remote", //数据从服务端读取
                            remoteFilter: true, //进一步过滤store
                            editable: false,
                            listeners: {
                                change: "changeEvent",
                                added: "eventListRender"
                            }
                        },
                        {
                            xtype: 'textfield',
                            fieldLabel: "发生河段",
                            labelWidth: 120,
                            reference: "locname",
                            editable: false,
                            width: 150,
                            emptyText: "发生河段",
                        },
                        {
                            xtype: "dicComboBox",
                            reference: "daType",
                            dicType: "daType",
                            fieldLabel: "污染物类型",
                            emptyText: "请选择污染物类型",
                            name: "daType",
                            bind: "{resource.daType}"
                        },
                        {
                            xtype: 'textfield',
                            fieldLabel: "发生河段",
                            hidden: true,
                            reference: "rcd",
                            value: 0
                                // bind: "{resource.rcd}"
                        },
                        {
                            xtype: "combobox",
                            reference: "method",
                            dicType: "method",
                            fieldLabel: "溯源方式",
                            emptyText: "请选择溯源方式",
                            valueField: "value",
                            displayField: "label",
                            name: "method",
                            listeners: {
                                change: "methodChange",
                                added: function(combo) {
                                    var _that = this;
                                    var store = Ext.create('Ext.data.Store', {
                                        fields: ['label', 'value'],
                                        data: [{
                                            "id": "9",
                                            "createDate": "2017-06-08 09:44:59",
                                            "updateDate": "2017-06-08 09:45:02",
                                            "value": "0",
                                            "label": "模拟计算",
                                            "type": "sourcemethod",
                                            "description": "溯源方式",
                                            "sort": 50,
                                            "parentId": "0",
                                            "createBy": "1",
                                            "updateBy": "1"
                                        }, {
                                            "id": "10",
                                            "createDate": "2017-06-08 09:46:14",
                                            "updateDate": "2017-06-08 09:46:17",
                                            "value": "2",
                                            "label": "人工填写",
                                            "type": "sourcemethod",
                                            "description": "溯源方式",
                                            "sort": 60,
                                            "parentId": "0",
                                            "createBy": "1",
                                            "updateBy": "1"
                                        }]
                                    });
                                    combo.setStore(store);
                                    combo.setValue(0);
                                },
                            },
                        },
                        {
                            xtype: "combobox",
                            reference: "upsec",
                            fieldLabel: "溯源上监测断面",
                            labelWidth: 120,
                            width: 150,
                            forceSelect: true,
                            bind: {
                                store: "{upsecStore}",
                                value: "{resource.upsec}"
                            },
                            editable: false,
                            emptyText: "请先选择河段",
                            name: "upsec",
                            valueField: "value",
                            displayField: "label"
                        },
                        {
                            xtype: "panel",
                            layout: {
                                type: "hbox",
                                align: "stretch"
                            },
                            items: [{
                                    xtype: "combobox",
                                    reference: "downsec",
                                    id: "zzsyDownsec",
                                    fieldLabel: "溯源下监测断面",
                                    labelWidth: 120,
                                    // forceSelect: true,
                                    labelAlign: "right",
                                    flex: 1,
                                    value: "self",
                                    editable: false,
                                    margin: "0 10 0 0",
                                    bind: {
                                        store: "{downsecStore}",
                                    },
                                    emptyText: "请先选择河段",
                                    name: "downsec",
                                    valueField: "value",
                                    displayField: "label",
                                    // selectionMode: "SINGLE",
                                    // listeners: {
                                    // 	change: "onHisDataReadClick"
                                    // }
                                },
                                {
                                    xtype: "button",
                                    reference: 'downsecbutton',
                                    width: 60,
                                    text: "详情",
                                    handler: 'onHisDataReadClick'
                                }
                            ]
                        },
                        {
                            xtype: "timesfield",
                            reference: "begt",
                            editable: false,
                            fieldLabel: "起始计算时间",
                            format: "Y-m-d H:i:s",
                            bind: "{resource.begt}",
                            listeners: {
                                change: function() {
                                    var edDt = this.nextSibling();
                                    edDt.setMinValue(this.value);
                                }
                            }
                        },
                        {
                            xtype: "timesfield",
                            reference: "edt",
                            editable: false,
                            fieldLabel: "结束计算时间",
                            format: "Y-m-d H:i:s",
                            bind: "{resource.edt}"
                        },
                        {
                            xtype: "combobox",
                            fieldLabel: "时间尺度",
                            reference: "tscale",
                            labelWidth: 120,
                            width: 150,
                            forceSelect: true,
                            editable: false,
                            name: "时间尺度",
                            value: 1,
                            valueField: "value",
                            displayField: "label",
                            store: {
                                fields: ["label", "value"],
                                data: [{
                                    label: "小时",
                                    value: 1
                                }]
                            }
                        },
                        {
                            xtype: "textfield",
                            fieldLabel: "平均流速（m/s）",
                            bind: "{resource.q}",
                            emptyText: "请输入平均流速",
                            reference: "avgflow"
                        }
                        // {
                        // 	xtype: "combobox",
                        // 	reference: "downsec",
                        // 	id: "zzsyDownsec",
                        // 	fieldLabel: "溯源下监测断面",
                        // 	labelWidth: 120,
                        // 	width: 150,
                        // 	forceSelect: true,
                        // 	editable: false,
                        // 	bind: {
                        // 		store: "{downsecStore}",
                        // 		// value: "{resource.downsec}"
                        // 	},
                        // 	emptyText: "请先选择河段",
                        // 	name: "downsec",
                        // 	valueField: "value",
                        // 	displayField: "label",
                        // 	selectionMode: "SINGLE",
                        // 	listeners: {
                        // 		change: "onHisDataReadClick"
                        // 	}
                        // },

                    ],
                    bbar: [
                        "->",
                        {
                            xtype: "button",
                            iconCls: "x-fa fa-play",
                            reference: "symlBotton",
                            text: "溯源模拟",
                            handler: "imitateTrack"
                        }
                    ]
                },
                {
                    xtype: "form",
                    title: "溯源结果",
                    border: true,
                    flex: 0.45,
                    layers: "anchor",
                    margin: "10 0 0 0",
                    defaults: {
                        anchor: "100%",
                        margin: "10 10 0 10",
                        labelWidth: 80,
                        labelAlign: "right"
                    },
                    items: [{
                            xtype: "timesfield",
                            fieldLabel: "发生时间",
                            bind: "{resource.tm}",
                            editable: false,
                            reference: "tmResult",
                            format: "Y-m-d H:i:s",
                        },
                        {
                            // xtype: "combobox",
                            xtype: 'textfield',
                            reference: "loc",
                            id: 'zzsyRcd',
                            fieldLabel: "发生区域",
                            emptyText: "发生区域",
                            bind: "{resource.loc}"
                        },
                        {
                            xtype: "textfield",
                            fieldLabel: "断面距离(km)",
                            bind: "{resource.lenUp}",
                            reference: "surfaceDistanceResult"
                        },
                        {
                            xtype: "panel",
                            layout: {
                                type: "hbox",
                                align: "stretch"
                            },
                            items: [{
                                    xtype: "fieldcontainer",
                                    fieldLabel: "坐标",
                                    labelAlign: "right",
                                    labelWidth: 80,
                                    anchor: "100%",
                                    flex: 1,
                                    layout: {
                                        type: "hbox",
                                        align: "stretch"
                                    },
                                    items: [{
                                            xtype: "textfield",
                                            flex: 1,
                                            readOnly: true,
                                            reference: "lgtd",
                                            margin: "0 5 0 0",
                                            bind: "{resource.lgtd}",
                                            emptyText: "经度"
                                        },
                                        {
                                            xtype: "textfield",
                                            flex: 1,
                                            readOnly: true,
                                            reference: "lttd",
                                            bind: "{resource.lttd}",
                                            margin: "0 5 0 0",
                                            emptyText: "纬度"
                                        }
                                    ]
                                },
                                {
                                    xtype: "button",
                                    reference: 'locationBtn',
                                    width: 60,
                                    text: "定位",
                                    // handler: 'locationMap'
                                }
                            ]
                        },
                        {
                            xtype: "textfield",
                            fieldLabel: "持续时间(h)",
                            bind: "{resource.dur}",
                            reference: "continueTm"
                        },
                        {
                            xtype: "textfield",
                            fieldLabel: "污染量(Kg)",
                            bind: "{resource.da}",
                            reference: "pollutionLoad"
                        }
                    ],
                    bbar: {
                        items: [
                            "->",
                            {
                                xtype: "button",
                                iconCls: "x-fa fa-save",
                                text: "保存",
                                handler: "saveData"
                            }
                        ]
                    }
                }
            ]
        }
    ]
});

//断面设置
Ext.define("Admin.view.emergencyDispatch.HisDataRead", {
    extend: "Ext.panel.Panel",
    xtype: "hisDataRead",
    alias: "widget.hisDataRead",
    layers: "fit",
    items: [{
            xtype: 'form',
            reference: 'hisDataReadform',
            layout: 'form',
            border: true,
            items: [{
                    xtype: 'textfield',
                    labelWidth: '80',
                    labelAlign: 'right',
                    allowBlank: false,
                    name: 'secnm',
                    reference: 'secname',
                    fieldLabel: '断面名称'
                },
                {
                    xtype: 'numberfield',
                    name: 'lenup',
                    labelWidth: '80',
                    allowBlank: false,
                    reference: 'secmils',
                    labelAlign: 'right',
                    fieldLabel: '距上断面里程(km)'
                },
                {
                    xtype: "fieldcontainer",
                    fieldLabel: "断面位置",
                    labelAlign: "right",
                    labelWidth: 80,
                    reference: "lgtdlttd",
                    anchor: "100%",
                    flex: 1,
                    layout: {
                        type: "hbox",
                        align: "stretch"
                    },
                    items: [{
                            xtype: "textfield",
                            flex: 1,
                            name: "lgtd",
                            reference: "lgtd",
                            margin: "0 10 0 0",
                            emptyText: "经度"
                        },
                        {
                            xtype: "textfield",
                            flex: 1,
                            reference: "lttd",
                            name: "lttd",
                            margin: "0",
                            emptyText: "纬度"
                        }
                    ]
                }
            ]
        },
        {
            type: 'panel',
            border: true,
            height: 50,
            layout: "column",
            items: [{
                xtype: "button",
                width: 120,
                text: "<span style='color:#606060'>下载模板</span>",
                margin: '8',
                style: {
                    backgroundColor: '#f6f6f6',
                    borderColor: '#e4e4e4',
                },
                handler: 'downloadFile'
            }, {
                xtype: "form",
                // hidden:true,
                items: [{
                    xtype: "filefield",
                    msgTarget: "side",
                    name: 'fileuploadfield',
                    buttonOnly: true,
                    hideLabel: true,
                    anchor: "100%",
                    buttonText: "<span style='color:#606060'>导入数据</span>",
                    buttonConfig: {
                        style: {
                            backgroundColor: '#f6f6f6',
                            borderColor: '#e4e4e4',
                            margin: '8px',
                            width: '120px',
                        },
                    },
                    listeners: {
                        change: function() {
                            var evenCd = Ext.getCmp("zzsyEventCd").getValue();
                            var downsec = Ext.getCmp("zzsyDownsec").getValue();
                            var rcd = Ext.getCmp("zzsyRcd").getValue();
                            // console.log('evenCd', evenCd)
                            var form = this.up("form").getForm();
                            if (form.isValid()) {
                                form.submit({
                                    url: config.URL + "emergency/DdsEdWqData/importdata",
                                    waitMsg: "正在上传文件...",
                                    success: function(fp, o) {
                                        Ext.Msg.alert(
                                            "成功",
                                            '"你的文件"' + o.result.file + '"已经上传成功"'
                                        );
                                    },
                                    params: {
                                        evenCd: evenCd,
                                        downsec: downsec,
                                        rcd: rcd,
                                        river: config.RIVER
                                    }
                                });
                            }
                        }
                    }
                }]
            }]
        },
        {
            xtype: "baseGridPanel",
            cls: "grid-window-title",
            height: 300,
            reference: "surfaceSettingGrid",
            border: true,
            plugins: {
                ptype: "cellediting",
                clicksToEdit: 2
            },
            listeners: {
                validateedit: 'surfaceSettingGridEdit'
            },
            columns: [{
                    text: 'river',
                    dataIndex: 'river',
                    hidden: true
                },
                {
                    text: 'evenCd',
                    dataIndex: 'evenCd',
                    hidden: true
                },
                {
                    text: 'downsec',
                    dataIndex: 'downsec',
                    hidden: true
                },
                {
                    text: "时间",
                    dataIndex: "tm",
                    flex: 1,
                },
                {
                    text: "浓度(mg/L)",
                    flex: 1,
                    dataIndex: "c",
                    editor: {
                        allowBlank: false
                    },
                    renderer: function(value, record) {
                        return '<span style="color: #35baf6">' + value + '</span>'
                    }
                }
            ]
        }
    ]
});